//
//  PlanDetailCell.m
//  XhlTrip
//
//  Created by dllo on 15/8/27.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "PlanDetailCell.h"
#import "UIImageView+WebCache.h"

@implementation PlanDetailCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.cellDic = [NSMutableDictionary dictionary];
        self.mage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.mage];
        [_mage release];
        
        
        self.desLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.desLabel];
        self.desLabel.numberOfLines = 0;
        _desLabel.font = [UIFont fontWithName:@"Verdana-Italic" size:16 * Width];

        [_desLabel release];
        
        self.arealabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.arealabel];
        [_arealabel release];
        _arealabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:16 * Width];

        
        
        
        
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
   
    /* 判断是否为空  好分配位置 */
    if (![[self.cellDic allKeys] containsObject:@"entry_name"] || [self.cellDic objectForKey:@"entry_name"] == nil)
    {
        self.arealabel.text = @"今日备忘";
    }else
    {
        self.arealabel.text = [self.cellDic objectForKey:@"entry_name"];
        
    }
    
        self.arealabel.frame = CGRectMake(10 * Width, 10 * Height, self.contentView.frame.size.width - 30 * Width, 30 * Height);
    

    if (![[self.cellDic allKeys] containsObject:@"image_url"] || [self.cellDic objectForKey:@"image_url"] == nil){
        self.mage.frame = CGRectMake(0, 0, 0, 0);
        
    }else
    {
        [self.mage sd_setImageWithURL:[self.cellDic objectForKey:@"image_url"]];
        
        self.mage.frame = CGRectMake(10 * Width, 45 * Height, self.contentView.frame.size.width - 20 * Width, 150 * Height);
      
    }
    if ([[self.cellDic allKeys] containsObject:@"memo"] && [self.cellDic objectForKey:@"memo"] != nil){
        
        self.desLabel.text = [self.cellDic objectForKey:@"memo"];
        
        CGFloat height = [[self class] heightWithText:self.desLabel.text width:self.contentView.frame.size.width];
        self.desLabel.frame = CGRectMake(10 * Width, 45 * Height + self.mage.frame.size.height + 10 * Height , self.contentView.frame.size.width - 20 * Width, height);
        
    }else if ([[self.cellDic allKeys] containsObject:@"tips"] && [self.cellDic objectForKey:@"tips"] != nil){
        
        self.desLabel.text = [self.cellDic objectForKey:@"tips"];
        CGFloat height = [[self class] heightWithText:self.desLabel.text width:self.contentView.frame.size.width];
        self.desLabel.frame = CGRectMake(10 * Width, 45 * Height + self.mage.frame.size.height + 10 * Height , self.contentView.frame.size.width - 20 * Width, height + 5 * Height);
    }else
    {
        self.desLabel.frame = CGRectMake(0, 0, 0, 0);
    }

    
}
+ (CGFloat)heightWithText:(NSString *)text width:(CGFloat )width
{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Verdana-Italic" size:17 * Width]} context:nil];
    return rect.size.height;
}

- (void)dealloc
{
    [_cellDic release];
    [_arealabel release];
    [_mage release];
    [_desLabel release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
